<link rel="stylesheet" href="https://uicdn.toast.com/tui-editor/latest/tui-editor.css"/>
<link rel="stylesheet" href="https://uicdn.toast.com/tui-editor/latest/tui-editor-contents.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.33.0/codemirror.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css"/>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div style="margin-bottom: 10px;">
                <button id="btnMdGetData" class="layui-btn layui-btn-sm" type="button">获取内容</button>
            </div>
            <div id="demoMdEditor"></div>
        </div>
    </div>
</div>

<script>
    if (undefined == window.tui) {
        layui.jquery('#demoMdEditor').text('加载中...');
        layui.jquery.getScript('https://uicdn.toast.com/tui-editor/latest/tui-editor-Editor-full.js', function () {
            layui.jquery('#demoMdEditor').html('');
            init();
        });
    } else {
        init();
    }

    function init() {
        layui.use(['layer'], function () {
            var $ = layui.jquery;
            var layer = layui.layer;

            // 渲染编辑器
            var insEdt = new tui.Editor({
                el: document.querySelector('#demoMdEditor'),
                initialEditType: 'markdown',
                previewStyle: 'vertical',
                height: '300px'
            });

            // 获取内容
            $('#btnMdGetData').click(function () {
                var content = insEdt.mdEditor.editorContainerEl.outerText;  // 获取到内容
                layer.prompt({
                    shade: .1,
                    offset: '35px',
                    title: '源码',
                    skin: 'layui-layer-admin layui-layer-prompt',
                    formType: 2,
                    value: content,
                    btn: []
                });
            });

        });
    }
</script>